#ifndef __conn_track_h__
#define __conn_track_h__ 1
#ifdef BRIDGE_MODE_SUPPORT
#include "sys.h"
#include "net.h"
#include "tcp.h"
#include "capture.h"

enum {
    CONN_TUPLE_DIRECT = 0,
    CONN_TUPLE_REPLY = 1,
    CONN_TUPLE_MAX,
};



typedef struct {
    char ifname[32];
    struct ethhdr eth_hdr;
    struct vlanhdr vlan_hdr;
    struct ppphdr ppp_hdr;
    uint32_t my_ip;
    uint32_t dns_server;
} conn_base_info_t;

struct _tuple {
    uint32_t dest_ip, src_ip;
    uint16_t dest_port, src_port;
    uint16_t icmpId;
    uint32_t proto;
};
typedef struct _tuple conn_track;

struct conn_tcp_info{
    int status;
    uint32_t sent_seq, rcv_seq;
};


struct conn_entry {
    struct _tuple tuple[CONN_TUPLE_MAX];
    int fd;
    struct conn_tcp_info tcp_info;
    int refcnt;
    TAILQ_ENTRY(conn_entry)
    tailq;
};

#define conn_entry_set_status(entry, st)    (entry->tcp_info.status = st)

int conn_track_regist(conn_track *ct);
int conn_track_init(int argc, char** argv);
int conn_track_hook(Packet_t* ipkt);
void conn_base_set_ifname(char *ifname);
void conn_base_set_ethhdr(char* dmac, char* smac, uint16_t proto);
void conn_base_set_vlanhdr();
void conn_base_set_ppphdr();
void conn_base_set_myip(uint32_t saddr);
void conn_base_set_nameserver(uint32_t addr);
uint32_t conn_dns_server();
int conn_tcp_connect(conn_track *ct, int fd);
#endif //BRIDGE_MODE_SUPPORT
#endif